<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%@page import="java.sql.Date"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="startup.model.trip.AdvanceCompensation"%>
<%@page import="startup.model.trip.MissionRequest"%>
<%@page import="startup.model.trip.PaymentMethod"%>
<%@page import="startup.model.trip.Vehicle"%>
<%@page import="startup.model.user.Student"%>
<%@page import="startup.utils.DateTool"%>
<%@page import="startup.utils.Query"%>
<%
	try
	{
		Student student = ( Student )session.getAttribute( "currentSessionUser" );
		student.completeAttributesFromWorkingDB();

		int missionId = Integer.parseInt( request.getParameter( "tripId" ) );
		MissionRequest missionRequest = ( ( Student )session.getAttribute( "currentSessionUser" ) ).getHistory().getMissionById( missionId );
		session.setAttribute( "missionRequest", missionRequest );

		MissionRequest toSubmit = ( MissionRequest )session.getAttribute( "missionRequest" );
%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="windows-1252">
        <title>Modify Mission Request</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <!-- Le styles -->
        <link href="styles/bootstrap.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
    </head>
    <body>
        <!--Barra Superiore-->
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="brand" href="#">Student : <%=student.getSurname()%> <%=student.getName()%> </a>
                    <div class="nav pull-right">
                        <ul class="nav">
                            <li>
                                <form action="Logout" method="post">
                                    <button class="btn btn-primary btn-small">Sign out</button>
                                </form>
                            </li>
                        </ul>
                    </div>
                </div><!--/.fluid-container-->
            </div>
        </div>
        <form action="studentSubmitModifiedMission.jsp" method="post">
            <div class="container-fluid">
                <div class="row-fluid">
                    <div class="span3" style="position:fixed;"> 
                        <div class="well sidebar-nav">
                            <ul class="nav nav-list">
                                <li class="nav-header">Location</li>
                                <li><a href="studentChooseHistoryToShow.jsp"><i class="icon-home"></i> Home</a></li>
                                <li><a href="studentActualHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> ACTIVE History</a></li>
                                <li class="active"><a href="#"> &nbsp;&nbsp;&nbsp; &bull; <i class="icon-white icon-tasks"></i> Complete the forms </a></li>
                                <li><a href="studentTerminatedHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> TERMINATED History</a></li>
                                <li><a href="studentDeletedHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> DELETED History</a></li>
                                <li class="nav-header">Function</li>
                                <li><a href="studentNewMissionRequestSubmission.jsp"><i class="icon-pencil"></i> New Mission Request</a></li>
                                <li><a href="studentShowNewAdvanceCompensation.jsp"><i class="icon-pencil"></i> New Advance Compensation</a></li>
                                <li><a href="studentShowNewReimbursement.jsp"><i class="icon-pencil"></i> New Reimbursement</a></li>
                                <li class="divider"></li>
                                <li><a href="studentFAQ.jsp"><i class="icon-info-sign"></i> F.A.Q.</a></li>             
                            </ul>
                        </div><!--/.well -->
                    </div><!--/span-->
                    <div class="span9" style="margin-left: 26%;">
                        <div class="row-fluid">
                            <div class="hero-unit">
                                <h1>Modify Mission</h1>                        
                            </div>
                            <div class="tabbable">
                                <ul class="nav nav-tabs">
                                    <li><a href="#tab1" data-toggle="tab">Mission Request</a></li>
                                    <%
										AdvanceCompensation advanceCompensation = toSubmit.getAdvanceCompensation();
										if( advanceCompensation != null )
										{
                                    %>
                                    <li><a href="#tab2" data-toggle="tab">Advance Compensation</a></li>
                                    <%                                        }
                                    %>
                                </ul>
                                <div class="tab-content">
                                    <div class="tab-pane" id="tab1">
                                        <div class="row-fluid">
                                            <div class="span5">
                                                <h2>
                                                    Travel information:
                                                </h2>
                                                <br />
                                                <br />
                                                <h4>Planned Destination</h4>
                                                <br/>
                                                <input name="destination" type="text" value="<%=toSubmit.getDestination()%>"/> 
                                                <br />
                                                <br />
                                                <h4>Current address</h4>
                                                <br />
                                                <input name="currentAddress" type="text" value="<%=toSubmit.getCurrentAddress()%>"/>
                                                <br />
                                                <br />
                                                <h4>Number of nights</h4>
                                                <br />
                                                <input name="nights" type="number" value="<%=toSubmit.getNumberOfNights()%>" />
                                                <br />
                                                <br />
                                                <h4>Planned start date</h4>
                                                <br />
                                                <input name="startDate" type="date" value="<%=toSubmit.getPlannedStartDate()%>" />
                                                <br />
                                                <br />
                                                <h4>Planned end date</h4>
                                                <br />
                                                <input name="endDate" type="date" value="<%=toSubmit.getPlannedEndDate()%>" />
                                                <br />
                                                <br />  
                                                <h4>Reason for travel</h4>
                                                <br />
                                                <textarea name="reason" cols="42" rows="8" ><%=toSubmit.getPlannedReasonForTravel()%></textarea>
                                                <br />
                                                <br /> 
                                                <h4>Is a stop over requested during your trip?</h4>
                                                <br />
                                                <input name="isStopover" type="radio" value="true" <%if( toSubmit.getIsStopoverRequested() )
													{%>checked="true"<%}%>/> Yes
                                                <input name="isStopover" type="radio" value="false" <%if( !toSubmit.getIsStopoverRequested() )
													{%>checked="true"<%}%>/> No
                                                <br />
                                                <br /> 
                                                <h4>If yes, why?</h4>
                                                <br />
                                                <textarea name="stopoverReason" cols="35" rows="2"><%=toSubmit.getReasonForStopover()%></textarea>
                                                <br />
                                                <br /> 
                                            </div>
                                            <div class="span5">
                                                <h2>Transportation:</h2>
                                                <br />
                                                <br />
                                                <textarea name="planned_means_of_transports" rows="4" cols="42"><%= toSubmit.getMeansOfTransport()%></textarea>
                                                <br />
                                                <br />
                                                <h4>Type of transportation</h4>
                                                <br />
                                                <select name="typeOfTransportation">
                                                    <option value="BUSINESS" <%if( toSubmit.getTypeOfTransportation().equals( Vehicle.BUSINESS ) )
														{%>selected<%}%>>BUSINESS</option>
                                                    <option value="ORDINARY" <%if( toSubmit.getTypeOfTransportation().equals( Vehicle.ORDINARY ) )
														{%>selected<%}%>>ORDINARY</option>
                                                    <option value="EXTRAORDINARY" <%if( toSubmit.getTypeOfTransportation().equals( Vehicle.EXTRAORDINARY ) )
														{%>selected<%}%>>EXTRAORDINARY</option>
                                                </select>
                                                <br />
                                                <br />
                                                <h4>(Compile only if you are going with a private vehicle)</h4>
                                                <h4>Model:</h4>
                                                <br />
                                                <input type="text" name="modelOfPrivateVehicle" value="<%= toSubmit.getModel()%>"/>
                                                <br />
                                                <br />
                                                <h4>License Plate</h4>
                                                <br />
                                                <input type="text" name="license_plate" value="<%= toSubmit.getLicense()%>">
                                                <br />
                                                <br />
                                            </div>
                                        </div>
                                        <hr />
                                        <div class="row-fluid">
                                            <div class="span5">
                                                <h2>Funds information:</h2>
                                                <br />
                                                <br />
                                                <h4>Are you going to use personal fund?</h4>
                                                <br/>
                                                <input name="personalFund" type="radio" value="true" <%if( toSubmit.getArePersonalFundsUsed() )
													{%>checked="true"<%}%>/> Yes
                                                <input name="personalFund" type="radio" value="false" <%if( !toSubmit.getArePersonalFundsUsed() )
													{%>checked="true"<%}%> /> No
                                                <br />
                                                <br />
                                                <h4>  Are you going to use your external fund?  </h4>
                                                <br/>
                                                <input name="externalFund" type="radio" value="true" <%if( toSubmit.getFirstAlternativeFundManagerId() != null && toSubmit.getFirstAlternativeFundManagerId() > 0 )
													{%>checked="true"<%}%>/> Yes
                                                <input name="externalFund" type="radio" value="false" <%if( toSubmit.getFirstAlternativeFundManagerId() == null || toSubmit.getFirstAlternativeFundManagerId() <= 0 )
													{%>checked="true"<%}%>/> No
                                                <br />
                                                <br />
                                                <h4> Define your extra fund name: </h4>
                                                <br/>
                                                <input name="secondFundName" type="text" value="<%=toSubmit.getSecondAlternativeFundName()%>" />
                                                <br />
                                                <br />
                                            </div>
                                            <div class="span5">
                                                <h2>
                                                    Other information:
                                                </h2>
                                                <br />
                                                <br />
                                                <h4>Other declarations</h4>
                                                <br />
                                                <textarea name="otherDeclarations" cols="42" rows="8" ><%=toSubmit.getOtherDeclarations()%></textarea>
                                                <br />
                                                <br />
                                                <h4>(If you chose extraordinary type of transportation)</h4>
                                                <h4> Reason for extraordinary transport </h4>
                                                <br />
                                                <textarea name="reasonExtraordinaryTransport" cols="42" rows="8" ><%=toSubmit.getReasonForExtraordinaryTransport()%></textarea>
                                            </div>
                                        </div>
                                    </div><!-- chiusa tab1-->
                                    <%
										if( advanceCompensation != null )
										{
                                    %>
                                    <div class="tab-pane" id="tab2">
                                        <div class="row-fluid">
                                            <div class="span5">
                                                <h2>
                                                    Data you have before the mission:
                                                </h2>
                                                <br />
                                                <br />
                                                <h4>
													Registration fee for the mission
												</h4>
                                                <br />
                                                <input name="registrationFee" type="number" value="<%=advanceCompensation.getRegistrationFee()%>" />
                                                <br />
                                                <br />
                                                <h4>
                                                    Tickets
                                                </h4>
                                                <br />
                                                <div class="thumbnail">
                                                    <h4> Departure: </h4>
                                                    <h4> From: </h4>
                                                    <input name="fromDeparture" type="text" value="<%=advanceCompensation.getDepartureFrom()%>">
                                                    <h4> To: </h4>
                                                    <input name="toDeparture" type="text" value="<%=advanceCompensation.getDepartureTo()%>">
                                                    <h4> Date: </h4>
                                                    <input name="dateDeparture" type="date" value="<%=advanceCompensation.getDepartureDate()%>">
                                                </div>
                                                <br />
                                                <br />
                                                <div class="thumbnail">
                                                    <h4> 
														Return:
                                                    </h4>
                                                    <h4> From: </h4>
                                                    <input name="fromReturn" type="text" value="<%=advanceCompensation.getReturnFrom()%>">
                                                    <h4> To: </h4>
                                                    <input name="toReturn" type="text" value="<%=advanceCompensation.getReturnTo()%>">
                                                    <h4> Date: </h4>
                                                    <input name="dateReturn" type="date" value="<%=advanceCompensation.getReturnDate()%>">
                                                </div>                                    
                                            </div>
                                            <div class="span5">
                                                <h2>
                                                    Costs that you foresee:
                                                </h2>
                                                <br />
                                                <br />
                                                <h4>
                                                    Foreseen transportation costs
                                                </h4>
                                                <br />
                                                <input name="foreseenTransportation" type="number" value="<%=advanceCompensation.getForeseenTransportationCost()%>" />
                                                <br />
                                                <br />
                                                <h4>
                                                    Foreseen lodging costs
                                                </h4>
                                                <br />
                                                <input name="foreseenLodging" type="number" value="<%=advanceCompensation.getForeseenLodgingCost()%>" />
                                                <br />
                                                <br />
                                                <h4>
                                                    Foreseen meals costs
                                                </h4>
                                                <br />
                                                <input name="foreseenMeals" type="number" value="<%=advanceCompensation.getForeseenMealsCost()%>" />
                                            </div>
                                        </div>
                                        <hr />
                                        <div class="row-fluid">
                                            <div class="span5">
                                                <h2>
                                                    The amount you want to withdraw:
                                                </h2>
                                                <br />
                                                <br />
                                                <%
													if( toSubmit.getArePersonalFundsUsed() )
													{
                                                %>
                                                <h4>
                                                    Personal funds amount: <%= student.getPersonalFunds()%> <br />
                                                    How many personal funds do you want to use? 
                                                </h4>
                                                <br/>
                                                <input name="personalFundAmount" type="number" value="<%=advanceCompensation.getPersonalFundsAmount()%>" />
                                                <br />
                                                <br />
                                                <%                                            }
													if( toSubmit.getFirstAlternativeFundName() != null &&
														!toSubmit.getFirstAlternativeFundName().equals( "" ) )
													{
                                                %>
                                                <div class="thumbnail">
                                                    <h4>
														Fund name:
													</h4> 
													<br />
													<%= toSubmit.getFirstAlternativeFundName()%>
                                                    <br />
                                                    <br />
                                                    <h4>
                                                        First external fund amount:
                                                    </h4>
                                                    <br/>
                                                    <input name="firstFundAmount" type="number" value="<%=advanceCompensation.getFirstAlternativeFundAmount()%>" />
                                                </div>
                                                <br />
                                                <br />
                                                <%}
													if( toSubmit.getSecondAlternativeFundName() != null &&
														!toSubmit.getSecondAlternativeFundName().equals( "" ) )
													{
                                                %>
                                                <div class="thumbnail">
                                                    <h4>
                                                        Fund name:
                                                        <br />
                                                        <%= toSubmit.getSecondAlternativeFundName()%>
                                                    </h4>
                                                    <br />
                                                    <br />
                                                    <h4> Second external fund amount: </h4>
                                                    <br/>
                                                    <input name="secondFundAmount" type="number" value="<%=advanceCompensation.getSecondAlternativeFundAmount()%>" />
                                                </div>
                                                <br />
                                                <br />
                                                <%}%>  
                                            </div>
                                            <div class="span5">
                                                <h2>
                                                    How you wish to be paid:
                                                </h2>
                                                <br />
                                                <br />
                                                <h4>
                                                    Method of payment:
                                                </h4>
                                                <br />
                                                <input name="paymentMethod" type="radio" value="CASH" <%if( advanceCompensation.getPaymentMethod().equals( PaymentMethod.CASH ) )
													{%>checked<%}%>/> Cash
                                                <br />
                                                <input name="paymentMethod" type="radio" value="BANK" <%if( advanceCompensation.getPaymentMethod().equals( PaymentMethod.BANK ) )
													{%>checked<%}%>/> Bank Account 
                                            </div>
                                        </div>
                                    </div><!-- chiusa tab2-->
                                    <%}%>
                                </div><!-- chiusa tab-content-->
                            </div><!-- chiusa tabbable-->
                            <hr />
                            <div class="row-fluid">
                                <table>
                                    <tr>                                                    
                                        <td>
                                            <a class="btn btn-primary" data-toggle="modal" href="#Submit" >Submit</a>    
                                            <!--MODAL che appare quando si clicca su Refuse-->
                                            <div class="modal hide fade" id="Submit">
                                                <div class="modal-header">
                                                    <button class="close" data-dismiss="modal">x</button>
                                                    <h3>Are You Sure?</h3>
                                                </div>
                                                <div class="modal-body">
                                                    <p>Click "Save Changes" to SUBMIT the trip, Close instead.</p>
                                                </div>
                                                <div class="modal-footer">    
                                                    <table>
                                                        <tr>                                                    
                                                            <td>
                                                                <button class="btn btn-primary btn-success">Save Changes</button>
                                                            </td>
                                                            <td>
                                                                <button class="btn" data-dismiss="modal">Close</button>
                                                            </td>
                                                        </tr>
                                                    </table>  
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <button class="btn btn-primary" type="reset"  >Reset</button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div><!-- chiusa row fluid-->
                </div><!-- chiusa row fluid-->
            </div><!-- chiusa span9-->
        </form>
		<div class="navbarCC navbar-fixed-bottom">
			<div class="navbarCC-inner">
				<div class="container-fluid">				
					<a class="brand" href="#">&copy; 2012 Startup</a>					
				</div>
			</div>
		</div>
		<!-- Il javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.js"></script>
	</body>
</html>
<%
	}
	catch( RuntimeException runtimeException )
	{
		if( runtimeException.getClass().equals( NullPointerException.class ) )
		{
			runtimeException = new NullPointerException( "The session has timed out:<br />" + "" +
														 "try reloading page.<br />" +
														 "If the problem persists, please report it to the administration." );
		}
		request.setAttribute( "exception", runtimeException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
%>